package com.logistics.delivery.controller;

import com.logistics.delivery.entity.model.DeliveryAndPickPager;
import com.logistics.delivery.entity.model.DeliverySave;
import com.logistics.delivery.service.DeliveryService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;


@Controller
@RequestMapping("lgs/delivery")
public class DeliveryController {

    @Autowired
    private DeliveryService deliveryService;

    /**
     * 保存配送单
     *
     * @param save
     * @return
     */
    @PutMapping("save")
    public ResponseEntity save(@RequestBody DeliverySave save) throws MessageException {
        deliveryService.save(save);
        return ResponseUtil.success();
    }

    /**
     * 立即配送
     *
     * @param pickId
     * @return
     * @throws MessageException
     */
    @PutMapping("/immediately/{pickId}")
    @LoggerListener(businessName = "创建配送单", methodName = LoggerMethod.SAVE)
    public ResponseEntity immediately(@PathVariable("pickId") String pickId) throws MessageException {
        deliveryService.createDelivery(pickId);
        return ResponseUtil.success();
    }

    @PostMapping("/findDeliveryList")
    @LoggerListener(businessName = "查询配送单", methodName = LoggerMethod.SEARCH)
    public ResponseEntity findDeliveryList(@RequestBody DeliveryAndPickPager params) throws MessageException {
        return ResponseUtil.success(deliveryService.findDeliveryList(params));
    }

    @GetMapping("/getTabFilters")
    @LoggerListener(businessName = "获取PDA配送单查询Tab栏查询条件", methodName = LoggerMethod.SEARCH)
    public ResponseEntity getTabFilters() throws MessageException {
        return ResponseUtil.success(deliveryService.getFilterList());
    }

}
